<?php
/**
 * (exporter)
 */
namespace App\Exporter\Stocking;

use App\Models\Product\ProductClassify;
use App\Models\Stocking\StockingApplyDetail;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class DetailExporter extends ExcelExporter implements WithMapping
{

    protected $fileName = '备货单明细.csv';

    protected $headings = ['备货单号','站点','备货员','SKU','产品名称','季节性','品类','备货数量','状态','预计到货时间','创建日期'];

    public function map($model) : array
    {
        return [
            $model->stocking_no,
            $model->area->area ?? '',
            User::getUsernameById($model->apply->seller_id),
            $model->sku->psku_code ?? '',
            $model->sku->psku_cn ?? '',
            ProductClassify::$_season[$model->skuClassify->season ?? 3],
            $model->skuClassify->title ?? '',
            $model->apply_detail_num ?: 0,
            StockingApplyDetail::$_status[$model->status],
            $model->commit_date,
            $model->created_at,
        ];
    }
}
